package com.lagou;


import com.lagou.bean.ConsumerComponent;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class AnnotationConsumerMain {
    private static final Logger LOG = LoggerFactory.getLogger(AnnotationConsumerMain.class);

    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        ConsumerComponent component = app.getBean(ConsumerComponent.class);
        app.start();
        System.out.println("请输入回车，开始调用服务");
        System.in.read();
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 20, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100));
        while (true) {
            threadPoolExecutor.submit(() -> component.callABC('A', "sayhello"));
            threadPoolExecutor.submit(() -> component.callABC('B', "sayhello2"));
            threadPoolExecutor.submit(() -> component.callABC('C', "sayhello3"));
            Thread.sleep(60);
        }


    }


    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @EnableDubbo(scanBasePackages = "com.lagou.bean")
    @ComponentScan("com.lagou.bean")
    static class ConsumerConfiguration {

    }


}
